package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.StrategyReplyUserComment;
import cn.wolfcode.trip.base.domain.StrategyUserComment;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.StrategyReplyUserCommentMapper;
import cn.wolfcode.trip.base.query.StrategyUserCommentQuery;
import cn.wolfcode.trip.base.mapper.StrategyUserCommentMapper;
import cn.wolfcode.trip.base.service.IStrategyUserCommentService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyUserCommentServiceImpl implements IStrategyUserCommentService {

    @Autowired
    private StrategyUserCommentMapper userCommentMapper;
    @Autowired
    private StrategyReplyUserCommentMapper replyUserCommentMapper;

    @Override
    public PageInfo<StrategyUserComment> selectByStrategyCommentId(StrategyUserCommentQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyUserComment> list= userCommentMapper.selectByStrategyCommentId(qo);
        return new PageInfo<>(list) ;
    }

    @Override
    public void saveUserComment(StrategyUserComment userComment) {
        userComment.setUser(UserContext.getCurrentUser());
        userCommentMapper.insert(userComment);
    }

    @Override
    public void saveReplyUserComment(StrategyReplyUserComment replyUserComment) {
        replyUserComment.setUser(UserContext.getCurrentUser());
        replyUserCommentMapper.insert(replyUserComment);
    }

    @Override
    public int selectTotalCountForUnreadComment() {
        return  userCommentMapper.selectTotalCountForUnreadComment(UserContext.getCurrentUser());
    }

    @Override
    public List<StrategyComment> selectComment() {
        User user = UserContext.getCurrentUser();
        Boolean read= false;
        return userCommentMapper.selectComment(user.getId(),read);
    }

    @Override
    public void updateRead(Long strategyCommentId) {
        userCommentMapper.updateRead(strategyCommentId);
    }

    /**
     * 通过点评id查出该点评下的评论id集合
     * @param strategyCommentId
     * @return
     */
    @Override
    public List<Long> selectIdsByStrategyCommentId(Long strategyCommentId) {
        return userCommentMapper.selectIdsByStrategyCommentId(strategyCommentId);
    }
}
